﻿<cfsilent>
	<cfscript>

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		propertyAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
		
		subjectId = event.getArg('SubID');
		
		termDateStart = year( now() );
		
		/* 当前在校生判断 grade + schooling_length > ? */
		if ( month( now() ) < 9 ) {
			termDateStart = termDateStart - 1;
		}
		
		sql = "SELECT  
					t_subject.sbj_id, t_subject.sbj_name,
					t_institute.institute_id, t_institute.institute_name 
				FROM 
					t_subject 
					INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
				WHERE 
					t_subject.sbj_id = :subjectId ";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
   		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
		
		rs_subjectEntity = queryObj.execute( sql=sql ).getResult();
		
		sql = "SELECT 
					t_subject.sbj_id, t_subject.sbj_name, t_subject.term_start, t_subject.level_code, count(t_class.cls_id) count_clsId 
				FROM 
					t_class 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
				WHERE 
					t_subject.institute_id = :depID 
				GROUP BY 
					t_subject.sbj_id, t_subject.sbj_name, t_subject.term_start, t_subject.level_code  
				ORDER BY 
					t_subject.sbj_name ";
								
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="depID", value=rs_subjectEntity.institute_id, cfsqltype="cf_sql_varchar" );
		
		rs_subject = queryObj.execute( sql=sql ).getResult();
	
		
		sql = "SELECT 
					t_class.grade, 
					count(t_class.cls_id) count_clsId, 
					sum(t_class.cls_size) sum_clsSize, 
					sum(t_class.cls_scale) sum_clsScale 
				FROM 
					t_class 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id   
				WHERE  
					t_subject.sbj_id = :subjectId 
					AND 
					(t_class.grade + t_subject.schooling_length) > :yearNow 
				GROUP BY 
					t_class.grade 
				ORDER BY 
					t_class.grade DESC";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
		queryObj.addParam( name="subjectId", value=rs_subjectEntity.sbj_id, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="yearNow", value=termDateStart, cfsqltype="cf_sql_decimal", scale=1  );
		
		rs_grade = queryObj.execute( sql=sql ).getResult();
												
		
		event.setArg("pageTitle", "教学运行基础数据 - 学生学籍 - 专业班级设置 - " & rs_subject.sbj_name);
		
		currentTab = event.getArg("TabID", "labFormClass");
		
		if ( rs_grade.recordCount and currentTab eq "labFormClass" ) {
			currentTab = "labGrade" & rs_grade["grade"][1];
		}
		
		if ( len(event.getArg('Grade')) ) {
			currentTab = "labGrade" & event.getArg('Grade');
		}
		
		targetArgs = structNew();
		
		passArgs = structNew();
		structInsert(passArgs, "SubID", rs_subjectEntity.sbj_id, true);
		
		
		/* 搜索学生档案 */
		keyword = event.getArg("Keywords");
		
		rs_student = queryNew("stu_id,stu_name,cls_name,student_prop");
		
		if ( len(keyword) ) {
			
			sql = "SELECT 
						t_student.stu_id, t_student.stu_name, t_class.cls_name, t_student_status.student_prop 
					FROM 
						t_student 
						INNER JOIN i_stu_class_info b ON b.stu_id = t_student.stu_id 
						INNER JOIN t_class ON t_class.cls_id = b.cls_id 
						INNER JOIN t_student_status ON t_student_status.stu_id = t_student.stu_id 
					WHERE 
						t_class.sbj_id = :subjectId 
						AND 
						t_student.stu_id LIKE :condition 
						OR 
						t_student.stu_name LIKE :condition 
					ORDER BY 
						t_student.stu_name ";
					
			queryObj = new Query( datasource=application.dnsSlave, maxRows=60 ) ;
			queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="condition", value=keyword&"%" , cfsqltype="cf_sql_varchar" );
			
			rs_student = queryObj.execute( sql=sql ).getResult();
			
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('studentProfile')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">学籍档案</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#rs_subjectEntity.sbj_name#</cfoutput>专业班级设置
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<cfloop query="rs_grade">
							<span <cfif currentTab eq "labGrade" & rs_grade.grade>class="active"</cfif> id="labGrade<cfoutput>#rs_grade.grade#</cfoutput>" tabTarget="Grade<cfoutput>#rs_grade.grade#</cfoutput>"><cfoutput>#rs_grade.grade#</cfoutput>级</span>
						</cfloop>
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">搜索学生档案</span>
						<!---<span <cfif currentTab eq "labSubject">class="active"</cfif> id="labSubject" tabTarget="Subject">其他专业</span>--->
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<cfloop query="rs_grade">
					
					<cfset structInsert(passArgs, "Grade", rs_grade.grade, true) />
					<cfset structInsert(passArgs, "SubID", rs_subjectEntity.sbj_id, true) />
					
					<div id="Grade<cfoutput>#rs_grade.grade#</cfoutput>" class="tabContent">
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentBySubjectGradeDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载专业学生名单</span></a>
							</div><br/>
							<h3><cfoutput>#rs_grade.grade#</cfoutput>级</h3>
							<p><span class="img icon16x16 message"></span>共计<em><cfoutput>#rs_grade.count_clsId#</cfoutput></em>个行政班, 计划招生规模<em><cfoutput>#rs_grade.sum_clsSize#</cfoutput></em>人, 实际学生人数<em><cfoutput>#rs_grade.sum_clsScale#</cfoutput></em>.</p>
							<p>如果实际招生人数与计划人数出现较大偏差, 可以进行<a href="<cfoutput>#buildURL('classFlushBySubject', passArgs)#</cfoutput>">自动调整专业计划人数</a>.</p>
							<hr/>
						</div>
						
                        <cfset sql = "SELECT 
									(SELECT count(*) from i_stu_class_info a WHERE a.cls_id = t_class.cls_id) countStu,
									t_class.cls_id, t_class.cls_name, 
									t_class.cls_size, t_class.cls_scale, 
									t_campus.campus_name 
								FROM 
									t_class 
									INNER JOIN t_campus ON t_campus.campus_id = t_class.campus_id  
								WHERE 
									t_class.sbj_id = :subjectId 
									and 
									t_class.grade = :grade 
								ORDER BY 
									t_class.cls_name "/>
						    
				    <cfset queryObj = new Query( datasource=application.dnsSlave )/>
                        <cfset queryObj.addParam( name="subjectId", value=rs_subjectEntity.sbj_id, cfsqltype="cf_sql_varchar" )/>
                        <cfset queryObj.addParam( name="grade", value=rs_grade.grade, cfsqltype="cf_sql_char" )/>
                        
                        <cfset rs_class = queryObj.execute( sql=sql ).getResult()/>
                      
                      
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>班级</td>
									<td width="80">所在校区</td>
									<td width="60" align="center">计划人数</td>
									<td width="40" align="center">学生数</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_class">
									<cfset structInsert(targetArgs, "Class", rs_class.cls_id, true) />
									<cfset row++ />
									<tr class="editRows <cfif rs_class.cls_size lt rs_class.cls_scale>noticeRow1</cfif>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_class.cls_name#</cfoutput></td>
										<td><cfoutput>#rs_class.campus_name#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_class.cls_size#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_class.countStu#</cfoutput></span></td>
										<td><a class="stat info" href="<cfoutput>#buildURL('studentByClass', targetArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</div>
				</cfloop>
				
				<div id="Search" class="tabContent">
					
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('studentBySubject')#</cfoutput>">
						
						<input type="hidden" name="SubID" value="<cfoutput>#subjectId#</cfoutput>" />
						<input type="hidden" name="TabID" value="labSearch" />
						
						<div class="label">
							<b>学号或姓名</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
						</div>
						<hr/>
						<div class="lable">
							<input class="button1" type="submit" value="搜索" />
						</div>
					</form>
					
					<cfif rs_student.recordCount>

						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_student">
									
									<cfset structInsert(passArgs, "STU", rs_student.stu_id, true) />
									<cfset propertyAdvice.parseProperty(rs_student.student_prop) />
									
									<dl <cfif not propertyAdvice.getInSchool()>class="disabled"</cfif>>
										<dt>
											<a href="<cfoutput>#buildURL('studentProfileView', passArgs)#</cfoutput>">
												<em class="people"><!--imgholder--></em>
												<dd>
													<h3><cfoutput>#rs_student.stu_name#</cfoutput> - <cfoutput>#rs_student.cls_name#</cfoutput></h3>
													<p><cfoutput>#rs_student.stu_id#</cfoutput></p>
												</dd>
											</a>
										</dt>
									</dl>
								</cfloop>					
							</div>
						</div>
					
					</cfif>
					
				</div>
				
				<div id="Subject" class="tabContent">
					
					<cfset structDelete(targetArgs, "Class") />
					
					<div class="noticeBlock">
						<h3><cfoutput>#rs_subjectEntity.institute_name#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span>共计<em><cfoutput>#rs_subject.recordCount#</cfoutput></em>个招生专业, 点击专业名称查看行政班分布情况</p>
						<hr/>
					</div>
					
					<div class="clearfix">
						<div class="UICardTable">
                            <cfloop query="rs_subject">
								<cfset structInsert(targetArgs, "SubID", rs_subject.sbj_id, true) />
								<dl>
									<dt>
										<a href="<cfoutput>#buildURL('studentBySubject', targetArgs)#</cfoutput>">
											<em class="subject"><!--imgholder--></em>
											<dd>
												<h3><cfoutput>#rs_subject.sbj_name#</cfoutput></h3>
												<div><cfoutput>#dictAdvice.getTermEnrol(rs_subject.term_start)#-#dictAdvice.getStudentLevel(rs_subject.level_code)#-#rs_subject.count_clsId#个行政班</cfoutput></div>
											</dd>
										</a>
									</dt>
								</dl>
							</cfloop>
						</div>
					</div>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>

